package com.example.firstapp

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback

class intent4Activity : AppCompatActivity() {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.intent4)

        val extraData = intent.getStringExtra("send_data1")
        val ed:TextView = findViewById(R.id.textView2);  // 替换为你的TextView的id
        ed.append(extraData)

        // 点击后返回数据给上一层
        val result_bt:Button = findViewById(R.id.result_bt)
        result_bt.setOnClickListener {
            val intent = intent
            val result_data = findViewById<EditText>(R.id.editText3).getText().toString()
//            intent.putExtra("return_data",result_data)
//            Toast.makeText(this, result_data, Toast.LENGTH_SHORT).show()
//            setResult(RESULT_OK, intent)
            val returnIntent = Intent().apply {
                putExtra("return_data",result_data )
            }
            setResult(RESULT_OK, returnIntent) // 设置返回结果 [5]()[6]()
            finish()
        }

    }

}